package cn.ch.train.member.controller;

import cn.ch.train.common.context.LoginMemberContext;
import cn.ch.train.common.response.CommonResponse;
import cn.ch.train.common.response.PageResult;
import cn.ch.train.member.request.PassengerQueryParam;
import cn.ch.train.member.request.PassengerSaveParam;
import cn.ch.train.member.response.PassengerQueryResult;
import cn.ch.train.member.service.PassengerService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/passenger")
public class PassengerController {
    @Autowired
    private PassengerService passengerService;

    @PostMapping("/save")
    public CommonResponse save(@Valid @RequestBody PassengerSaveParam param) {
        passengerService.save(param);
        return new CommonResponse<>();
    }

    @GetMapping("/query-list")
    public CommonResponse<PageResult<PassengerQueryResult>> queryList(@Valid PassengerQueryParam param) {
        param.setMemberId(LoginMemberContext.getId());
        PageResult<PassengerQueryResult> passengerList = passengerService.queryList(param);
        return new CommonResponse<>(passengerList);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResponse delete(@PathVariable Long id) {
        passengerService.delete(id);
        return new CommonResponse<>();
    }

}
